import { BaseWindow } from "../../../../component/window/BaseWindow";
import { ILayer } from "../../../../mvc/interfaces/ILayer";
import { Language } from "../../../../../extend/language/Language";
import { ObjCreate } from "../../common/ObjCreate";
import { GTextFormat } from "../../../../common/GTextFormat";
import { FontUtil } from "../../../../common/font/FontUtil";
import { Cache } from "../../../cache/Cache";
import { RadioButtonGroup } from "../../../../../fl/controls/RadioButtonGroup";
import { PetExploreAreaInfo } from "../../../resource/info/PetExploreAreaInfo";
import { PetExploreConfig } from "../../../resource/PetExploreConfig";
import { Dispatcher } from "../../../../mvc/core/Dispatcher";
import { DataEvent } from "../../../events/DataEvent";
import { EventName } from "../../../mvc/EventName";
import { PetExploreAreaConfig } from "../../../resource/PetExploreAreaConfig";
import { GameDefConfig } from "../../../resource/GameDefConfig";
import { LayerManager } from "../../../manager/LayerManager";
import { EffectManager } from "../../../manager/EffectManager";
import { GCheckBox } from "../../../../../com/mui/controls/GCheckBox";
import { GButton } from "../../../../../com/mui/controls/GButton";
import { PetExploreConfigInfo } from "../../../resource/info/PetExploreConfigInfo";
type int = number;
//class PetExploreSkipWindow
    
    export  class PetExploreSkipWindow extends BaseWindow
    {
        constructor(arg1: ILayer=null)
        {
            super(arg1);
            this._configAreaArray = [];
            this.setSize(340, 230);
            this.titleHeight = 28;
            this.title = Language.getString(54513);
            return;
        }

        protected /* override */ createChildren(): void
        {
            super.createChildren();
            ObjCreate.createBg(17, 39, 305, 180, this);
            ObjCreate.createTextField(Language.getString(54514), 40, 45, 220, 20, this);
            ObjCreate.createTextField(Language.getString(54515), 40, 115, 300, 20, this);
            this._costCheckBox = ObjCreate.createCheckBox(Language.getString(54516), 40, 130, 220, 20, this);
            ObjCreate.createTextField(Language.getString(54517), 165, 133, 220, 20, this);
            this._costTxt = ObjCreate.createTextField(Language.getString(54518), 200, 133, 220, 20, this);
            this._tipTxt = ObjCreate.createTextField("", 40, 155, 220, 20, this, new GTextFormat(FontUtil.songtiName, 12, 65280));
            this._tipTxt.autoSize = flash.text.TextFieldAutoSize.LEFT;
            this._tipTxt.htmlText = Language.getString(54519);
            this._startBtn = ObjCreate.createGButton(Language.getString(54520), 135, 190, 70, 26, this);
            this._startBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onStartBtnClickHandler);
            return;
        }

        /* internal  */createAreaRb(arg1: Array<any>): void
        {
            var loc1=null;
            var loc2=null;
            this._selectedConfigInfo = Cache.instance.petExplore.selectedConfigInfo;
            this._rbSprite = new Object /* flash.display.Sprite */();
            this._rbSprite.x = 40;
            this._rbSprite.y = 60;
            this.addChild(this._rbSprite);
            this._rbRadioGroup = new RadioButtonGroup("rb");
            this._rbRadioGroup.addEventListener(flash.events.Event.CHANGE, this.onSelectChangeHandler);
            var loc3=0;
            while (loc3 < arg1.length) 
            {
                loc1 = arg1[loc3] as PetExploreAreaInfo;
                loc2 = ObjCreate.createRadioButton(loc1.name, loc3 % 4 * 70, Math.floor(loc3 / 4) * 18, 100, 20, this._rbSprite);
                loc2.group = this._rbRadioGroup;
                loc2.value = loc1;
                if (this._selectedConfigInfo.area == loc1.area) 
                {
                    loc2.selected = true;
                }
                ++loc3;
            }
            return;
        }

        /* internal  */onStartBtnClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            this._toExploreConfigInfo = PetExploreConfig.instance.getAreaFirstRoadblock(this._selectAreaInfo.area);
            var loc1=this._toExploreConfigInfo.level;
            var loc2=false;
            var loc3=this._costCheckBox.selected;
            Dispatcher.dispatchEvent(new DataEvent(EventName.PetExploreStart, {"startLevel": loc1, "isAutoExplore": loc2, "isDrawRewards": loc3, "callBack": this.onStartExploreReponse}));
            return;
        }

        /* internal  */onStartExploreReponse(): void
        {
            this.hide();
            Cache.instance.petExplore.selectedConfigInfo = this._toExploreConfigInfo;
            Dispatcher.dispatchEvent(new DataEvent(EventName.PetExploreBattleWindowOpen));
            Cache.instance.petExplore.initJoinPet();
            Dispatcher.dispatchEvent(new DataEvent(EventName.PetExploreSelectRb, this._toExploreConfigInfo.level));
            return;
        }

        /* internal  */onSelectChangeHandler(arg1: Object /* flash.events.Event */): void
        {
            var loc1=null;
            this._cost = 0;
            this._selectAreaInfo = this._rbRadioGroup.selectedData as PetExploreAreaInfo;
            this._unit = this._selectAreaInfo.drawUnit;
            var loc2=1;
            while (loc2 < this._selectAreaInfo.area) 
            {
                loc1 = PetExploreAreaConfig.instance.getAreaConfigByArea(loc2);
                this._cost = this._cost + loc1.drawCost;
                ++loc2;
            }
            this._costTxt.text = this._cost.toString() + GameDefConfig.instance.getEPrictUnitName(this._unit);
            return;
        }

        public /* override */ show(arg1: int=0, arg2: int=0): void
        {
            super.show(arg1, arg2);
            this._configAreaArray = Cache.instance.petExplore.getEnableAreaArray();
            this.createAreaRb(this._configAreaArray);
            LayerManager.highestLayer.addPopUp(this, true);
            LayerManager.highestLayer.centerPopup(this);
            EffectManager.addUIMask([], 0);
            return;
        }

        public /* override */ hide(): void
        {
            super.hide();
            LayerManager.highestLayer.removePopup(this);
            EffectManager.hideUIMask();
            Dispatcher.dispatchEvent(new DataEvent(EventName.PetExploreSelectRb, 1));
            return;
        }

        /* internal */ /* var */_rbSprite: Object /* flash.display.Sprite */;

        /* internal */ /* var */_rbRadioGroup: RadioButtonGroup;

        /* internal */ /* var */_costCheckBox: GCheckBox;

        /* internal */ /* var */_costTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_tipTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_startBtn: GButton;

        /* internal */ /* var */_configAreaArray: Array<any>;

        /* internal */ /* var */_cost: int;

        /* internal */ /* var */_unit: int;

        /* internal */ /* var */_selectAreaInfo: PetExploreAreaInfo;

        /* internal */ /* var */_selectedConfigInfo: PetExploreConfigInfo;

        /* internal */ /* var */_toExploreConfigInfo: PetExploreConfigInfo;
    }
